package com.star.common

import android.app.Activity
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import com.star.libwidget.star_popups.common.StarCommonPopup
import com.star.libwidget.star_popups.menu.StarPopupMenu
import kotlinx.android.synthetic.main.activity_popup_window.*

class PopupWindowActivity : AppCompatActivity(),View.OnClickListener {
    private var popupWindow: StarPopupMenu? = null
    companion object{
       fun start(activity: Activity){
           val intent = Intent(activity,PopupWindowActivity::class.java)
           activity.startActivity(intent)
       }
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_popup_window)
        //3
        val dataList = ArrayList<StarPopupMenu.ItemBean>()
        dataList.clear()
        dataList.add(StarPopupMenu.ItemBean(R.drawable.ic_setting_san_new, "第一个"))
        dataList.add(StarPopupMenu.ItemBean(R.drawable.ic_setting_san_new, "第二个"))
        dataList.add(StarPopupMenu.ItemBean(R.drawable.ic_setting_san_new, "第三个"))
        dataList.add(StarPopupMenu.ItemBean(R.drawable.ic_setting_san_new, "第四个"))
        dataList.add(StarPopupMenu.ItemBean(R.drawable.ic_setting_san_new, "第五个"))
        dataList.add(StarPopupMenu.ItemBean(R.drawable.ic_setting_san_new, "第六个"))
        popupWindow = StarPopupMenu(this,dataList)
        btn_pop_1.setOnClickListener(this)
        btn_pop_2.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when(v?.id){
            //弹框
            R.id.btn_pop_1 -> {
                popupWindow?.showAsDropDown(btn_pop_1, -400, 20)
                popupWindow?.setOnSelectListener(object : StarPopupMenu.SelectListener {
                    override fun onSelectListener(position: Int, name: String) {
                        Toast.makeText(applicationContext, position.toString()+name, Toast.LENGTH_SHORT).show()
                    }
                })
            }
            R.id.btn_pop_2 -> {
               val pop = StarCommonPopup(this)
                   .setText("啦啦啦啦")
                   .show(btn_pop_2,100,20)
            }
        }
    }
}